function [result] = haar_detection(IMG,haar)

haar_classifier = load(haar);
haar_classifier = haar_classifier.haar_trainning_output;

patch_size = 24;

IMG=double(IMG);
[height width] = size(IMG);

result = [];

for x=1:24:height - 23;
	for y=1:24:width - 23;
		flag = 1;
		scale = 1;
		step = 24;
		while flag == 1
			step = round(scale* step);
			x_real = x + step - 1;
			y_real = y + step - 1;
			if x_real > height || y_real > width
				flag = 0;
			else
				TEST = IMG(x:x_real,y:y_real);
				TEST = imresize(TEST,[24 24]);

				var_v = var(TEST(:));
				if var_v == 0
					var_v = 1;
				end
				TEST = (TEST- mean(TEST(:)))/sqrt(var_v);
				TEST= cumsum(cumsum(TEST),2);
				RET=is_this_face(TEST,haar_classifier);
				if RET == 1
					result(:,size(result,2)+1) = [x;y;x_real;y_real];
				end
				scale = 1.25;
			end
		end
	end
end

function [result] = is_this_face(IMG,haar)
result=[];

for x=1:size(haar,2)
	result(1,x) = haar_evaluate_feature(IMG,haar(1,x),haar(2,x),haar(3,x), haar(4,x),haar(5,x));
end
result = ((result .* haar(6,:)) < (haar(6,:).*haar(7,:)));
resulta = (result * (haar(10,:)'));
resultb =  (0.5 * sum( haar(10,:)));
result = resulta >= resultb;
